package date.yetao.maven.all.util;

/**
 * 日志的辅助工具
 *
 * @author yetao
 **/
public class LogUtils {

    public static final int LEVEL_DEBUG = 10;
    public static final int LEVEL_INFO = 20;
    public static final int LEVEL_WARN = 30;
    public static final int LEVEL_ERROR = 40;

    /**
     * 默认的日志级别
     */
    private static int level = LEVEL_WARN;

    public static void setLevel(int level) {
        LogUtils.level = level;
    }

    public static boolean isDebugEnable() {
        return LEVEL_DEBUG >= level;
    }

    public static boolean isInfoEnable() {
        return LEVEL_INFO >= level;
    }

    public static boolean isWarnEnable() {
        return LEVEL_WARN >= level;
    }

    public static boolean isErrorEnable() {
        return LEVEL_ERROR >= level;
    }

    public static void debug(String msg) {
        if (!isDebugEnable()) {
            return;
        }
        System.out.println("[DEBUG] " + msg);
    }

    public static void info(String msg) {
        if (!isInfoEnable()) {
            return;
        }
        System.out.println("[INFO] " + msg);
    }

    public static void warn(String msg) {
        if (!isWarnEnable()) {
            return;
        }
        System.out.println("[WARNING] " + msg);
    }

    public static void error(String msg) {
        if (!isErrorEnable()) {
            return;
        }
        System.out.println("[ERROR] " + msg);
    }

}
